package cn.edu.sgu.www.mhxysy.controller.system;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.entity.system.TableField;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.system.TableFieldService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "表字段管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@RestController
@RequestMapping(path = "/table_field", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class TableFieldController {

    private final TableFieldService tableFieldService;

    @Autowired
    public TableFieldController(TableFieldService tableFieldService) {
        this.tableFieldService = tableFieldService;
    }

    @ApiOperation("查询表的字段")
    @RequestMapping(value = "/selectFields", method = RequestMethod.GET)
    public JsonResult<List<TableField>> selectFields(
            @ApiParam(name = "tableName", value = "数据库表名", required = true)
            @NotBlank(message = "数据库表名" + CustomMessages.NOT_NULL) String tableName) {
        List<TableField> tableFields = tableFieldService.selectFields(tableName);

        return JsonResult.success(null, tableFields);
    }

}